<template>
  <Dialog
    v-model="dialogVisible"
    :title="t('judgeScene.initial.viewJudgeSubmitResult')"
    width="1200"
  >
    <ContentWrap>
      <!-- 搜索工作栏 -->
      <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">
        <el-form-item :label="t('scxFinalCandidate.judgeConfirm.submitResult')" prop="isConfirm">
          <el-select
            v-model="queryParams.isConfirm"
            :placeholder="
              t('common.selectTextPlaceholder') + t('scxFinalCandidate.judgeConfirm.submitResult')
            "
            clearable
            @change="handleQuery"
            class="!w-200px"
          >
            <el-option :label="t('judgeScene.initial.submited')" :value="true" />
            <el-option :label="t('judgeScene.initial.unsubmited')" :value="false" />
          </el-select>
        </el-form-item>
      </el-form>
    </ContentWrap>
    <vxe-table
      id="iJudgeResultList-table"
      v-loading="loading"
      :data="list"
      stripe
      :custom-config="vxeTableConfig"
      :column-config="{ resizable: true }"
      :size="vxeTableSize"
    >
      <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
      <vxe-column
        :title="t('scxFinalCandidate.judgeConfirm.mentorName')"
        field="mentorName"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      />
      <vxe-column
        :title="t('scxFinalCandidate.judgeConfirm.mentorCode')"
        field="mentorCode"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      />
      <vxe-column
        :title="t('scxFinalCandidate.judgeConfirm.submitResult')"
        field="confirmResult"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      >
        <template #default="scope">
          <span v-if="scope.row.confirmResult">{{ t('judgeScene.initial.submited') }}</span>
          <span v-else>{{ t('judgeScene.initial.unsubmited') }}</span>
        </template>
      </vxe-column>
    </vxe-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </Dialog>
</template>

<script setup lang="ts">
import { JudgesSubmitResVO, ReviewSceneApi } from '@/api/awards/reviewscene'
import type { VxeTablePropTypes } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'

defineOptions({ name: 'JudgeResultList' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const dialogVisible = ref(false) // 弹窗的是否展示
const loading = ref(true) // 列表的加载中
const list = ref<JudgesSubmitResVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  awardsInstanceId: undefined,
  roundId: undefined,
  isConfirm: undefined
})

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

const getList = async () => {
  loading.value = true
  queryParams.awardsInstanceId = awardsId.value as any
  queryParams.roundId = roundId.value as any
  try {
    const data = await ReviewSceneApi.getJudgesConfirmRoundList(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

const awardsId = ref('')
const roundId = ref('')
const open = async (_awardsId: string, _roundId: string) => {
  awardsId.value = _awardsId
  roundId.value = _roundId
  resetForm()
  dialogVisible.value = true
  getList()
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

const resetForm = () => {
  list.value = []
  total.value = 0
  queryParams.pageNo = 1
  queryParams.pageSize = 10
  queryParams.awardsInstanceId = undefined
  queryParams.roundId = undefined
  queryParams.isConfirm = undefined
}

defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
